<?php
error_reporting(E_ALL^E_NOTICE);
header('Content-Type:text/html;charset=gbk');

class LogGworkerCommand extends ConsoleCommand
{
    public function beforeRun(&$args)
    {
        return parent::beforeRun($args);
    }

    public function run($args = array())
    {
        $this->beforeRun($args);

        $this->_worker->addFunction('log.notify.swift.aliprepay', function($job){
            echo 'swift.ali.prepay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.ali.prepay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.alijspay', function($job){
            echo 'swift.ali.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.ali.jspay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.aliapppay', function($job){
            echo 'swift.ali.apppay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.ali.apppay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.wxprepay', function($job){
            echo 'swift.wx.prepay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.wx.prepay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.wxjspay', function($job){
            echo 'swift.wx.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.wx.jspay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.rollway2.swift.wxjspay', function($job){
            echo 'rollway2.swift.wx.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/rollway2.swift.wx.jspay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.wxapppay', function($job){
            echo 'swift.wx.apppay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.wx.apppay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.swift.wxwappay', function($job){
            echo 'swift.wx.wappay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/swift.wx.wappay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.pingan.wxjspay', function($job){
            echo 'pingan.wx.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/pingan.wx.jspay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.pingan.wxminipay', function($job){
            echo 'pingan.wx.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/pingan.wx.minipay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.roll.pingan.wxjspay', function($job){
            echo 'roll.pingan.wx.jspay notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/roll.pingan.wx.jspay.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        $this->_worker->addFunction('log.notify.shengpay.wx.order', function($job){
            echo 'shengpay.wx.order notifyLog is called at ' . date('Y-m-d H:i:s') . "\n";

            $workLoadArgs = json_decode($job->workload(), true);
            $info = $workLoadArgs['info'];

            $time = empty($time) ? time() : $time;
            $now = date('Y-m-d H:i:s', $time);
            $nowDay = date('Ymd-a');
            $handler = fopen(dirname(__DIR__) . '/allpay_logs/notilogs/shengpay.wx.order.' . $nowDay, 'a+');
            fputs($handler, $now . ': ' . $info . "\n\n");

            fclose($handler);
        });

        echo "Log Gworker is started\n";
        while ($this->_worker->work());
    }
}